﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsDMDonVi
    {
        private string mDiaChi = "";
        private string mDienThoai = "";
        private string mEmail = "";
        private string mEMNguoiDaiDien = "";
        private string mFax = "";
        private string mGhiChu = "";
        private string mKhoa = "";
        private string mMa = "";
        private string mMBNguoiDaiDien = "";
        private string mNguoiDaiDien = "";
        private string mPrefix = "";
        private int mSend = 0;
        private string mTDNguoiDaiDien = "";
        private string mTenAnh = "";
        private string mTenViet = "";

        public DataTable GetList()
        {
            IDataParameter parameter = null;
            DataTable table;
            try
            {
                string commandText = "SELECT * FROM DM_DonVi ORDER BY Ma, TenViet, TenAnh  Order by Ma, TenViet, TenAnh";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListField(string pField, string pConditions = "", string pOrder = "")
        {
            DataTable table;
            string str = "";
            string str2 = "";
            pField = pField.Replace("|", " , ");
            IDataParameter parameter = null;
            if (pConditions.Trim() != "")
            {
                str2 = " WHERE " + pConditions;
            }
            if (pOrder.Trim() != "")
            {
                str = " ORDER BY " + pOrder;
            }
            try
            {
                string commandText = "SELECT " + pField + " FROM DM_ChiNhanh " + str2 + str;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM DM_DonVi WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mMa = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mTenViet = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mTenAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDiaChi = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mDienThoai = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mFax = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mEmail = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mNguoiDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mTDNguoiDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mMBNguoiDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mEMNguoiDaiDien = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mGhiChu = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mPrefix = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetInt32));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable ShowList()
        {
            IDataParameter parameter = null;
            DataTable table;
            try
            {
                string commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as Ten FROM DM_DonVi ORDER BY 3 ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string DiaChi
        {
            get
            {
                return this.mDiaChi;
            }
            set
            {
                this.mDiaChi = value;
            }
        }

        public string DienThoai
        {
            get
            {
                return this.mDienThoai;
            }
            set
            {
                this.mDienThoai = value;
            }
        }

        public string Email
        {
            get
            {
                return this.mEmail;
            }
            set
            {
                this.mEmail = value;
            }
        }

        public string EmailNguoiDaiDien
        {
            get
            {
                return this.mEMNguoiDaiDien;
            }
            set
            {
                this.mEMNguoiDaiDien = value;
            }
        }

        public string Fax
        {
            get
            {
                return this.mFax;
            }
            set
            {
                this.mFax = value;
            }
        }

        public string GhiChu
        {
            get
            {
                return this.mGhiChu;
            }
            set
            {
                this.mGhiChu = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string Ma
        {
            get
            {
                return this.mMa;
            }
            set
            {
                this.mMa = value;
            }
        }

        public string MobileNguoiDaiDien
        {
            get
            {
                return this.mMBNguoiDaiDien;
            }
            set
            {
                this.mMBNguoiDaiDien = value;
            }
        }

        public string NguoiDaiDien
        {
            get
            {
                return this.mNguoiDaiDien;
            }
            set
            {
                this.mNguoiDaiDien = value;
            }
        }

        public string Prefix
        {
            get
            {
                return this.mPrefix;
            }
            set
            {
                this.mPrefix = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string TenAnh
        {
            get
            {
                return this.mTenAnh;
            }
            set
            {
                this.mTenAnh = value;
            }
        }

        public string TenViet
        {
            get
            {
                return this.mTenViet;
            }
            set
            {
                this.mTenViet = value;
            }
        }

        public string TieuDeNguoiDaiDien
        {
            get
            {
                return this.mTDNguoiDaiDien;
            }
            set
            {
                this.mTDNguoiDaiDien = value;
            }
        }
    }
}

